# -*- coding: utf-8 -*-

import time

# selenium 结合解析
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://tieba.baidu.com/f?kw=%E8%8F%9C%E8%B0%B1&ie=utf-8&pn=11500')
time.sleep(2)

# driver.switch_to.frame('iframe')
# 获取源码内容
# input()
html = driver.page_source
print(html)
while True:
    # 如果存在会返回一串数字， 如果不存在返回的-1
    # print(html.find('下一页eq21341233'))
    print(html.find('下一页'))
    if html.find('下一页') != -1:
        driver.find_element(By.CLASS_NAME, 'next').click()
        time.sleep(1)
    else:
        print('已经是最后一页了！')
        break